import axios from '@/utils/request';
import qs from 'qs';
const baseURL = process.env.VUE_APP_COMMON_API;

// 获取各消息状态下的消息数量
const messageStatus = () => {
  return axios.request({
    method: 'get',
    url: baseURL + '/message/message_status',
    headers: {
      hideLoading: true //是否显示loading
    }
  });
};

// 获取消息列表
const messageList = (params, hideLoading = true) => {
  return axios.request({
    method: 'get',
    url: baseURL + '/message/list',
    params,
    headers: {
      hideLoading //是否显示loading
    }
  });
};

// 获取消息详情
const messageDetail = params => {
  return axios.request({
    method: 'get',
    url: baseURL + '/message/detail',
    params,
    headers: {
      hideLoading: true //是否显示loading
    }
  });
};

// 清除未读消息
const clearUnreadMessage = data => {
  return axios.request({
    method: 'POST',
    url: baseURL + '/message/read',
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });
};

export { messageStatus, messageList, messageDetail, clearUnreadMessage };
